<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8" />
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<title>科转申请</title>
	<link href="layuiv29/css/layui.css" rel="stylesheet">
	<script src="layuiv29/layui.js"></script>
	<style>
	
		.login-header {
			color: rgba(0, 0, 0, .85) !important;
			padding: 3% 0;
			text-align: center;
		}

		.layui-text em,
		.layui-word-aux {
			color: #ef0909 !important;
			padding: 0 5px !important;
		}

		.layui-input-block {
			margin-left: 0;
			min-height: 46px;
			display: flex;
		}

		.buttongroup {
			display: flex;
			justify-content: center;
			margin-top: 20px;
		}

		.buttongroup button {
			width: 40%;
			height: 45px;
		}

		.main_content_wrap {
			margin: 20px 0px;
		}

		/*.layui-form select {
			display: block;
			width: 190px;
			height: 38px;
			padding-right: 30px;
			cursor: pointer;
			border-color: #D2D2D2 !important;
			padding-left: 10px;
		}*/

		/*.layui-unselect,
		.layui-form-select {
			display: none;
		}*/
		@media screen and (min-width: 800px) {
			.layui-form-label{
				width: 86px !important;
			}
			.sel-input-inline {
				width: 225px !important;
			}
		}

		.content_box{
			max-width: 960px;
		}
		.opendata-show{
			height: 38px;
			line-height: 38px;
		}
	</style>
</head>

<body>
	<div class="body">
		<div class="login-header">
			<h2 style="font-weight: 400;letter-spacing: 3px; font-size: 30px">科转申请</h2>
		</div>
		<div class="layui-fluid content_box">
			<div class="main_content_wrap">
				<form lay-filter="modifyForm" class="layui-form model-form">
					<div class="layui-form-item">
						<label class="layui-form-label">成果名称</label>
						<div class="layui-input-inline">
							<input name="name" type="text" autocomplete="off" class="layui-input" required />
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">所有权人</label>
						<div class="layui-input-inline">
							<select name="ownership" id="knowledge_ownership" required>
							</select>
						</div>

						<label class="layui-form-label">知识产权号</label>
						<div class="layui-input-inline">
							<input name="knowledge_num" type="text" autocomplete="off" required class="layui-input" />
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">知识产权类型</label>
						<div class="layui-input-inline sel-input-inline">
							<select name="knowledge_type" id="knowledge_type" lay-filter="knowledge_type" required>
							</select>
						</div>
						<div class="layui-input-inline sel-input-inline">
							<select name="knowledge_type_detail" id="type_second" disabled>
								<option value="">请选择</option>
							</select>
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">合同类别</label>
						<div class="layui-input-inline sel-input-inline">
							<select name="contract_type" lay-filter="contract_type" required id="contract_type">
							</select>
						</div>
						<div class="layui-input-inline sel-input-inline">
							<select name="contract_type_detail" id="conversion_get_second_level" disabled>
								<option value="">请选择</option>
							</select>
						</div>

					</div>
					
					<div class="layui-form-item">
						<label class="layui-form-label" style="width: 80px">产权有效日期</label>
						<div class="layui-input-inline" style="width: 100px;">
							<input type="text" name="knowledge_start_time" placeholder="开始时间" class="layui-input"
								id='starDate' required autocomplete="off">
						</div>
						<div class="layui-form-mid"> - </div>
						<div class="layui-input-inline" style="width: 100px;">
							<input type="text" name="knowledge_end_time" placeholder="结束时间" class="layui-input"
								id='endDate' required autocomplete="off">
						</div>
						
						<label class="layui-form-label">发明人</label>
						<div class="layui-input-inline">
							<input name="inventor" type="text" autocomplete="off" class="layui-input" required  placeholder="多个发明人用顿号分割"  />
						</div>
							<!-- <div class="layui-form-mid layui-word-aux">（）</div> -->
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">转化方式</label>
						<div class="layui-input-inline">
							<select name="conversion_type"  required id="conversion_type">
							</select>
						</div>

						<label class="layui-form-label">转化预收益</label>
						<div class="layui-input-inline">
							<input name="conversion_get_money" type="number" placeholder="请输入预收益" class="layui-input"
								required lay-verify="required|number|positiveNumber" autocomplete="off" />
						</div>

					
					</div>
					<hr>
					<div class="main_content_wrap">
						<p class="add_title">受让单位及法定代表人</p>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">单位全称</label>
						<div class="layui-input-inline">
							<input name="to_company_name" type="text" autocomplete="off" required class="layui-input" />
						</div>
						
						<label class="layui-form-label" style="width: 120px  !important;">统一社会信用代码</label>
						<div class="layui-input-inline">
							<input name="to_company_union_no" type="text" autocomplete="off" required
								lay-verify="required|socialCreditCode" class="layui-input" />
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">单位性质</label>
						<div class="layui-input-inline">
							<select name="unitnature_first" lay-filter="unitnature_first" required id="unitnature_first">
							</select>
						</div>
						<div class="layui-input-inline">
							<select name="unitnature_second" lay-filter="unitnature_second" id="unitnature_second" disabled>
								<option value="">请选择</option>
							</select>
						</div>
						<div class="layui-input-inline">
							<select name="unitnature_third" id="unitnature_third" disabled>
								<option value="">请选择</option>
							</select>
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">所在地区</label>
						<div class="layui-input-inline">
							<select name="province" lay-filter="province" id="province">
								<option value="">请选择</option>
							</select>
						</div>
						<div class="layui-input-inline">
							<select name="city" id="city" lay-filter="city" disabled>
								<option value="">请选择</option>
							</select>
						</div>
						<div class="layui-input-inline">
							<select name="district" id="district" disabled>
								<option value="">请选择</option>
							</select>
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">详细地址</label>
						<div class="layui-input-block">
							<input name="to_company_address_detail" type="text" autocomplete="off" required
								class="layui-input" />
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">法人姓名</label>
						<div class="layui-input-inline">
							<input name="to_company_legal_person" type="text" autocomplete="off" required
								class="layui-input" />
						</div>

						<label class="layui-form-label">联系电话</label>
						<div class="layui-input-inline">
							<input name="to_company_legal_phone" type="text" autocomplete="off" required
								lay-verify="required|phoneNum" class="layui-input" />
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">邮政编码</label>
						<div class="layui-input-inline">
							<input name="to_company_postal_code" type="text" autocomplete="off" required
								   class="layui-input" />
						</div>

						<label class="layui-form-label" style="width: 98px  !important;">是否为关联交易</label>
						<div class="layui-input-inline">
							<input type="radio" name="is_connected_transaction" title="否" value="否" checked/>
							<input type="radio" name="is_connected_transaction" title="是" value="是"  />
						</div>
					</div>
					<hr>
					<div class="main_content_wrap">
						<p class="add_title">主要完成人</p>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">姓名</label>
						<div class="layui-input-inline">
							<input name="main_finished_person_name" id="main_finished_person_name" required
								lay-verify="required" type="text" autocomplete="off" class="layui-input" />
						</div>

						<label class="layui-form-label">联系电话</label>
						<div class="layui-input-inline">
							<input name="main_finished_person_phone" id="main_finished_person_phone" required
								lay-verify="required|phoneNum" type="text" autocomplete="off" class="layui-input" />
						</div>

						<label class="layui-form-label">身份证号</label>
						<div class="layui-input-inline">
							<input name="main_finished_person_cardno" type="text" autocomplete="off"
								lay-verify="required|idcard" required class="layui-input" />
						</div>
					</div>
					<div class="main_content_wrap">
						
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">二级单位审批人</label>
						<div class="layui-input-inline">
							<input name="second_company_check_user" id="selUser" type="text" autocomplete="off"
								   lay-verify="required" required class="layui-input" />
						</div>
						<input hidden name="second_company_id" id="second_company_id"/>
						<label class="layui-form-label">二级单位名称</label>
						<div class="layui-input-inline">
							<input name="second_company" type="text" autocomplete="off"
								lay-verify="required" required class="layui-input" />
						</div>
					</div>
					<div class="layui-form-item text-center buttongroup">
						<button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog"  onclick="gonextpage()">取消</button>
						<button type="button" lay-filter="modifyFormSubmit" lay-submit
							class="layui-btn site-demo-active">确认</button>
					</div>
				</form>
			</div>
		</div>
	</div>

	<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
	<script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.4.0.js"></script>

	<script src="https://wwcdn.weixin.qq.com/node/open/js/wecom-jssdk-1.3.1.js"></script>
	<script src="https://open.work.weixin.qq.com/wwopen/js/jwxwork-1.0.0.js" referrerpolicy="origin"></script>
	<!-- 选择用户 -->
	<script type="text/html" id="authModel">
		<tree id="test13" class="ztree"></tree>
	</script>
	<script>
		layui.use(['jquery', 'form', 'upload', 'layer', 'laydate'], function () {
			var $ = layui.jquery;
			var form = layui.form;
			var layer = layui.layer;
			var laydate = layui.laydate;
			var upload = layui.upload;
			var router = layui.router();

			let userMsg = JSON.parse(localStorage.getItem("userMsg"));
			// 日期范围 - 左右面板独立选择模式
			var startDate = laydate.render({
				elem: '#starDate', //指定元素
				format: 'yyyy-MM-dd', //可任意组合
				trigger: 'click',
				done: function (value, date) {
					endDate.config.min = {
						year: date.year,
						month: date.month - 1, //关键
						date: date.date,
					};
				}
			});
			var endDate = laydate.render({
				elem: '#endDate', //指定元素
				format: 'yyyy-MM-dd', //可任意组合
				trigger: 'click',
				done: function (value, date) {
					startDate.config.max = {
						year: date.year,
						month: date.month - 1,//关键
						date: date.date,
					}
				}

			});
			
			console.log(serverUrl,"==================")

			if (!knowledgeTypeList) {
				$.get(serverUrl + 'Common/getListByType', {}, function (res) {
					if (res.success) {
						knowledgeTypeList = res.obj.knowledge_type;
						ownershipList = res.obj.ownership;
						conversionTypeList = res.obj.conversion_type;
						contractTypeList = res.obj.contract_type;
						unitnatureList = res.obj.to_company_type;
						arealist = res.obj.area_list;
						stateList = res.obj.state_list;
						setSel();
					}
				}, 'json');

			}else{
				setSel();
			}
			regSunccFun();
			function setSel() {
				function generateFirstLeveltype() {
					var conversion_type_str = '<option value="">请选择</option>';
					for (var i = 0; i < knowledgeTypeList.length; i++) {
						conversion_type_str += '<option value="' + knowledgeTypeList[i].name + '">' + knowledgeTypeList[i].name + '</option>';
					}
					$('#knowledge_type').html(conversion_type_str);
				}
				// 生成二级菜单
				function generateSecondLeveltype(selectedParent) {
					var secondLevelSelect = $('#type_second');
					secondLevelSelect.empty().append('<option value="">请选择</option>');
					if (selectedParent) {
						var selectedType = knowledgeTypeList.find(type => type.name === selectedParent);
						if (selectedType && selectedType.children) {
							for (var j = 0; j < selectedType.children.length; j++) {
								console.log(selectedType.children[j])
								secondLevelSelect.append('<option value="' + selectedType.children[j].name + '">' + selectedType.children[j].name + '</option>');
							}
						}
						secondLevelSelect.removeAttr('disabled'); // 启用二级菜单
					} else {
						secondLevelSelect.attr('disabled', true); // 禁用二级菜单
					}
				}
				// 初始化一级菜单
				generateFirstLeveltype();
				// 监听一级菜单的改变事件
				form.on('select(knowledge_type)',function (data) {
					var selectedOption = data.value;
					generateSecondLeveltype(selectedOption);
					form.render()
				});

				var knowledge_ownership_str = '<option value="">请选择</option>';
				for (var i = 0; i < ownershipList.length; i++) {
					knowledge_ownership_str += '<option value="' + ownershipList[i] + '">' + ownershipList[i] + '</option>';
				}
				$('#knowledge_ownership').html(knowledge_ownership_str);

				var conversion_type_str = '<option value="">请选择</option>';
				for (var i = 0; i < conversionTypeList.length; i++) {
					conversion_type_str += '<option value="' + conversionTypeList[i] + '">' + conversionTypeList[i] + '</option>';
				}
				$('#conversion_type').html(conversion_type_str);


				function generateFirstLevelOptions() {
					var contract_type_str = '<option value="">请选择</option>';
					for (var i = 0; i < contractTypeList.length; i++) {
						contract_type_str += '<option value="' + contractTypeList[i].name + '">' + contractTypeList[i].name + '</option>';
					}
					$('#contract_type').html(contract_type_str);
				}
				// 生成二级菜单
				function generateSecondLevelOptions(selectedParent) {
					var secondLevelSelect = $('#conversion_get_second_level');
					secondLevelSelect.empty().append('<option value="">请选择</option>');
					if (selectedParent) {
						var selectedType = contractTypeList.find(type => type.name === selectedParent);
						if (selectedType && selectedType.children) {
							for (var j = 0; j < selectedType.children.length; j++) {
								secondLevelSelect.append('<option value="' + selectedType.children[j].value + '">' + selectedType.children[j].name + '</option>');
							}
						}
						secondLevelSelect.removeAttr('disabled'); // 启用二级菜单
					} else {
						secondLevelSelect.attr('disabled', true); // 禁用二级菜单
					}
				}

				// 初始化一级菜单
				generateFirstLevelOptions();

				// 监听一级菜单的改变事件
				form.on('select(contract_type)',function (data) {
					var selectedOption = data.value;
					generateSecondLevelOptions(selectedOption);
					form.render()
				});

				// 单位性质
				// 生成一级菜单
				// 生成第一级菜单
				function generateFirstLevelunit() {
					var unitnature_first_str = '<option value="">请选择</option>';
					for (var i = 0; i < unitnatureList.length; i++) {
						unitnature_first_str += '<option value="' + unitnatureList[i].name + '">' + unitnatureList[i].name + '</option>';
					}
					$('#unitnature_first').html(unitnature_first_str);
				}

				// 初始化第一级菜单
				generateFirstLevelunit();

				// 监听第一级菜单变化
				form.on('select(unitnature_first)',function (data) {
					var selectedFirstLevel = data.value;

					// 清空并隐藏第二、三级菜单
					$('#unitnature_second').empty().attr('disabled', true).parent().hide();
					$('#unitnature_third').empty().attr('disabled', true).parent().hide();

					// 生成第二级菜单
					var secondLevelOptions = '';
					if (selectedFirstLevel) {
						var firstLevelData = unitnatureList.find(item => item.name === selectedFirstLevel);
						if (firstLevelData && firstLevelData.children && firstLevelData.children.length > 0) {
							secondLevelOptions = '<option value="">请选择</option>';
							for (var j = 0; j < firstLevelData.children.length; j++) {
								secondLevelOptions += '<option value="' + firstLevelData.children[j].name + '">' + firstLevelData.children[j].name + '</option>';
							}
							$('#unitnature_second').html(secondLevelOptions).attr('disabled', false).parent().show();

							// 预备生成第三级菜单的逻辑，这里假设第二级选择后会填充第三级
							form.on('select(unitnature_second)',function (data) {
								var selectedSecondLevel = data.value;
								var selectedFirst = $('#unitnature_first').val();
								var secondLevelData = firstLevelData.children.find(item => item.name === selectedSecondLevel);
								if (secondLevelData && secondLevelData.children && secondLevelData.children.length > 0) {
									var thirdLevelOptions = '<option value="">请选择</option>';
									for (var k = 0; k < secondLevelData.children.length; k++) {
										thirdLevelOptions += '<option value="' + secondLevelData.children[k].name + '">' + secondLevelData.children[k].name + '</option>';
									}
									$('#unitnature_third').html(thirdLevelOptions).attr('disabled', false).parent().show();
								} else {
									$('#unitnature_third').empty().attr('disabled', true).parent().hide();
								}
								form.render()
							});
						}
					}
					form.render()
				});


				generateFirstLevelarea();
				function generateFirstLevelarea() {
					var area_first_str = '<option value="">请选择</option>';
					for (var i = 0; i < arealist.length; i++) {
						area_first_str += '<option value="' + arealist[i].name + '">' + arealist[i].name + '</option>';
					}
					$('#province').html(area_first_str);
				}

				// 监听第一级菜单变化
				form.on('select(province)',function (data) {
					var selectedFirstLevel = data.value;
					// 清空并隐藏第二、三级菜单
					$('#city').empty().attr('disabled', true);
					$('#district').empty().attr('disabled', true);

					// 生成第二级菜单
					var secondLevelOptions = '';
					if (selectedFirstLevel) {
						var firstLevelData = arealist.find(item => item.name === selectedFirstLevel);
						if (firstLevelData && firstLevelData.city && firstLevelData.city.length > 0) {
							secondLevelOptions = '<option value="">请选择</option>';
							for (var j = 0; j < firstLevelData.city.length; j++) {
								secondLevelOptions += '<option value="' + firstLevelData.city[j].name + '">' + firstLevelData.city[j].name + '</option>';
							}
							$('#city').html(secondLevelOptions).attr('disabled', false);
							form.render();
							// 预备生成第三级菜单的逻辑，这里假设第二级选择后会填充第三级
							form.on('select(city)',function (data) {
								var selectedSecondLevel = data.value;
								var selectedFirst = $('#province').val();
								var secondLevelData = firstLevelData.city.find(item => item.name === selectedSecondLevel);
								if (secondLevelData && secondLevelData.district && secondLevelData.district.length > 0) {
									var thirdLevelOptions = '<option value="">请选择</option>';
									for (var k = 0; k < secondLevelData.district.length; k++) {
										thirdLevelOptions += '<option value="' + secondLevelData.district[k].name + '">' + secondLevelData.district[k].name + '</option>';
									}
									$('#district').html(thirdLevelOptions).attr('disabled', false).parent().show();
								} else {
									$('#district').empty().attr('disabled', true);
								}
								form.render();
							});
						}
					}
				});
				form.render();
			}
			form.render();

			$('#selUser').on('click', function () {

			});

			/*$('#selUser').on('click', function () {
				document.getElementById('userData').setAttribute('openid', '');
				WWOpenData.bind(document.querySelector('ww-open-data'));
				selectEnterpriseContact('user','single',[],[],
						function (res) {
							const openid = res.ids[0]
							$('#second_company_id').val(openid)
							document.getElementById('userData').setAttribute('openid', openid);
							WWOpenData.bind(document.querySelector('ww-open-data'));
							form.render();
						},
						function (err) {
							console.log('选择失败：', err)
						}
				)
			});
*/

			//监听提交
			form.on('submit(modifyFormSubmit)', function (data) {
				// var DISABLED = 'layui-btn-disabled';
				// // 增加样式
				// $('.site-demo-active').addClass(DISABLED);
				// // 增加属性
				// $('.site-demo-active').attr('disabled', 'disabled');
				data.field.add_userid = userMsg.UserId;
				data.field.add_department_id =  Array.isArray(userMsg.department)?userMsg.department.join(','):userMsg.department;
				data.field.to_company_addresss_area = data.field.province+'-'+data.field.district+'-'+data.field.city;
				data.field.to_company_type = data.field.unitnature_first+'-'+data.field.unitnature_second+'-'+data.field.unitnature_third;
				
				$.post(serverUrl + 'Knowledge/addInfo.html', data.field, function (res) {
					if (res.success === true) {
						layer.msg('提交成功', { icon: 1, time: 3000 }, function () {
							window.location.href = `turnrecord.html`;
						});
					} else {
						layer.msg(res.msg, { icon: 2 });
						// $('.site-demo-active').removeClass(DISABLED);
						// $('.site-demo-active').removeAttr('disabled');
					}
				}, 'json');
				return false;
			});


			form.verify({
				numberDh: function (value, item) {
					var reg = /^[0-9]+(,[0-9]+)*$/; // 正则表达式，匹配数字和逗号
					if (!reg.test(value)) {
						return '请输入正确的金额';
					}
				},
				socialCreditCode: function (Code) {
					let reg = /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;
					if (!reg.test(Code)) {
						var patrn = /^[0-9A-Z]+$/;
						//18位校验及大写校验
						if ((Code.length != 18) || (patrn.test(Code) == false)) {
							return '不是有效的身份证号或统一社会信用编码';
						} else {
							var Ancode;//统一社会信用代码的每一个值
							var Ancodevalue;//统一社会信用代码每一个值的权重
							var total = 0;
							var weightedfactors = [1, 3, 9, 27, 19, 26, 16, 17, 20, 29, 25, 13, 8, 24, 10, 30, 28];//加权因子
							var str = '0123456789ABCDEFGHJKLMNPQRTUWXY';
							//不用I、O、S、V、Z
							for (var i = 0; i < Code.length - 1; i++) {
								Ancode = Code.substring(i, i + 1);
								Ancodevalue = str.indexOf(Ancode);
								total = total + Ancodevalue * weightedfactors[i];
								//权重与加权因子相乘之和
							}
							var logiccheckcode = 31 - total % 31;
							if (logiccheckcode == 31) {
								logiccheckcode = 0;
							}
							var Str = "0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,J,K,L,M,N,P,Q,R,T,U,W,X,Y";
							var Array_Str = Str.split(',');
							logiccheckcode = Array_Str[logiccheckcode];

							var checkcode = Code.substring(17, 18);
							if (logiccheckcode != checkcode) {
								return '不是有效的身份证号或统一社会信用编码';
							}
						}
					}
				},
				positiveNumber: [/^(([0-9]+[\.]?[0-9]+)|[1-9])$/, '请输入正确的金额'],
				email: [/^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$/, '请填写正确的邮箱号'],
				phoneNum: [/^1\d{10}$/, '请填写正确的手机号'],
				idcard: [/^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/, '请填写正确的身份证号码'],
			});
		});
		
		function gonextpage(params) {
			window.location.replace('main.html');
		}
	</script>
</body>

</html>